//
//  RouteDetailMessageCell.m
//  Cycling
//
//  Created by 迟国强 on 2023/4/5.
//

#import "RouteDetailMessageCell.h"
#import "RouteDetailModel.h"

@implementation RouteDetailMessageCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.bgView.layer.cornerRadius = 16;
    self.bgView.layer.masksToBounds = YES;
    // Initialization code
}
- (IBAction)clickedCollectionBtn:(UIButton *)sender {
    self.collectionBlock(self.model);
}
- (IBAction)clickedGoodBtn:(UIButton *)sender {
    self.goodBlock(self.model);
}

- (void)setModel:(RouteDetailModel *)model {
    _model = model;
    self.routeNameL.text = model.name;
    [self.collectionBtn setTitle:model.collectionnum forState:UIControlStateNormal];
    [self.goodBtn setTitle:model.praisenum forState:UIControlStateNormal];

    if (model.iscollection) {
        [self.collectionBtn setTitleColor:rgbHex(0x0AD39F, 1) forState:UIControlStateNormal];
        [self.collectionBtn setImage:[UIImage imageNamed:@"收藏_select"] forState:UIControlStateNormal];
    } else {
        [self.collectionBtn setTitleColor:rgbHex(0x303030, 1) forState:UIControlStateNormal];
        [self.collectionBtn setImage:[UIImage imageNamed:@"收藏"] forState:UIControlStateNormal];
    }
    if (model.ispraise) {
        [self.goodBtn setTitleColor:rgbHex(0x0AD39F, 1) forState:UIControlStateNormal];
        [self.goodBtn setImage:[UIImage imageNamed:@"点赞_select"] forState:UIControlStateNormal];
    } else {
        [self.goodBtn setTitleColor:rgbHex(0x303030, 1) forState:UIControlStateNormal];
        [self.goodBtn setImage:[UIImage imageNamed:@"点赞"] forState:UIControlStateNormal];
    }
    self.distanceL.text = [NSString stringWithFormat:CycLocalizedString(@"Distance: %.1fmiles", @"全长：%.1fmiles"), CSMeterToMileage(model.actualdistance.floatValue)];
    self.finshDistanceL.text = [NSString stringWithFormat:CycLocalizedString(@"Distance to route: %.1fmiles", @"距离该线路：%.1fmiles"), [self distanceBetweenOrderBy:[model.startlat doubleValue] lat2:self.lat lng1:[model.startlng doubleValue] lng2:self.lng]];
    self.contentL.text = model.introduce;
}

-(double)distanceBetweenOrderBy:(double)lat1 lat2:(double)lat2 lng1:(double)lng1 lng2:(double)lng2 {
    
    CLLocation *curLocation = [[CLLocation alloc] initWithLatitude:lat1 longitude:lng1];
    CLLocation *otherLocation = [[CLLocation alloc] initWithLatitude:lat2 longitude:lng2];
    double  distance  = [curLocation distanceFromLocation:otherLocation];
    return  CSMeterToMileage(distance);
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
